/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import org.htmlparser.Parser;
import org.htmlparser.lexer.Page;
import org.htmlparser.lexer.Lexer;
import java.io.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;

/**
 *
 * @author Sinem
 */
public class RuleChecker implements Runnable{
    
    private List<String> m_asFilesToCheck;    

    public RuleChecker()
    {
        m_asFilesToCheck = new ArrayList();
    }

    public void addFileToBeChecked(String fileName)
    {
        m_asFilesToCheck.add(new String(fileName));       
    }
    public void run()
    {
       InputStream inputFile = null;
       Parser parser = null;              
       Iterator index = m_asFilesToCheck.iterator();
       String fileName = "";
       while (index.hasNext())
       {   
           fileName = (String)index.next();
           try{            
            inputFile = new FileInputStream(fileName);
            RuleVisitor visitor = new RuleVisitor(fileName);
            parser = new Parser(new Lexer(new Page(inputFile,"UTF-8")));
            parser.visitAllNodesWith(visitor);
          }catch(Exception e){
              parser.reset();
              e.printStackTrace();
              try
              {                  
                  inputFile = new FileInputStream(fileName);
                  RuleVisitor visitor = new RuleVisitor(fileName);
                  parser = new Parser(new Lexer(new Page(inputFile,"ISO-8859-9")));
                  parser.visitAllNodesWith(visitor);
              }
              catch(Exception ex)
              {
                  parser.reset();
                  ex.printStackTrace();
                  try
                  {                     
                     inputFile = new FileInputStream(fileName);
                     RuleVisitor visitor = new RuleVisitor(fileName);
                     parser = new Parser(new Lexer(new Page(inputFile,"windows-1254")));
                     parser.visitAllNodesWith(visitor);
                  }catch(Exception xx)
                  {
                  }
              }
          };
       }     
    }
}
